﻿namespace _06_C_中五种创建线程的方法
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.Title = "C#5种创建线程的方法";

            //No1
            new Thread(() =>
            {
                Console.WriteLine($"Thread线程,线程ID:{Thread.CurrentThread.ManagedThreadId}");
            }).Start();

            //No2
            ThreadPool.QueueUserWorkItem((p) =>
            {
                Console.WriteLine($"线程池创建线程,线程ID:{Thread.CurrentThread.ManagedThreadId}");
            });

            //No3
            Task.Run(() =>
            {
                Console.WriteLine($"Task任务,线程ID:{Thread.CurrentThread.ManagedThreadId}");
            });

            //No4
            TaskFactory taskFactory = new TaskFactory();
            taskFactory.StartNew(() => Console.WriteLine($"Task工厂创建线程,线程ID:{Thread.CurrentThread.ManagedThreadId}"));

            //No5 委托创建目前.net6.0应该不支持
            Action action = () => Console.WriteLine($"委托异步执行,线程ID:{Thread.CurrentThread.ManagedThreadId}");
            action.BeginInvoke(null, null);

            Console.WriteLine($"主线程Id:{Thread.CurrentThread.ManagedThreadId}");

            Console.ReadKey();
        }
    }
}
